package com.ly.designpatten.single;

/**
 * @Classname LazySingleSafe
 * @Description TODO
 * @Date 2020/10/5 14:37
 * @Author 冷心影翼
 */
public class LazySingleSafe {


	private static LazySingleSafe lazySingleSafe;

	private LazySingleSafe() {
		System.out.println("init");
	}

	public static LazySingleSafe getInstance() {
		if(lazySingleSafe == null) {
			synchronized (LazySingleUnsafe.class) {
				if(lazySingleSafe == null)
					lazySingleSafe = new LazySingleSafe();
			}
		}
		return lazySingleSafe;
	}
}

class TestLazySingleSafe {
	public static void main(String[] args) {

		for(int i=0;i<10;i++) {
			new Thread(()->{LazySingleSafe.getInstance();}).start();
		}
	}
}